package com.jasperframework.boot.common.utils;

import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.validation.BindingResult;

import java.util.stream.Collectors;

/**
  * <p> controller 层使用 JPA 的参数校验工具 </p>
  *
  * @site https://miliqkdoc.motopa.cn/
  * @author daizhao
  * @date 2019-11-05 16:10
  */
public class ValidateCheckUtil {
    public static String validate(BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return bindingResult.getAllErrors().stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining(","));
        } else {
            return null;
        }
    }
}
